package J20250227_dfs;

import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:日志统计——https://www.lanqiao.cn/problems/179/learning/
 * User: 王圆豪
 * Date: 2025-03-26
 * Time: 20:30
 */


public class Main9 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int d = scan.nextInt();
        int k = scan.nextInt();
        HashMap<Integer, List<Integer>> map = new HashMap<>();
        PriorityQueue<Integer> q = new PriorityQueue<>();
        for(int i = 0; i < n; i++){
            int ts = scan.nextInt();
            int id = scan.nextInt();
            if(!map.containsKey(id)){
                map.put(id,new ArrayList<>());
                q.add(id);
            }
            map.get(id).add(ts);
        }
        while(!q.isEmpty()){
            int id = q.poll();
            List<Integer> l = map.get(id);
            l.sort((a,b)->a.compareTo(b));
            int first = 0, last = k-1;
            for(; last < l.size(); last++,first++){
                if(l.get(last)-l.get(first) < d){
                    System.out.println(id);
                    break;
                }
            }
        }
        scan.close();
    }
}